﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SqlSugar;
using Study.Model;

namespace WpfApp4
{
    /// <summary>
    /// MyDataGridView.xaml 的交互逻辑
    /// </summary>
    public partial class MyDataGridView : Window
    {
        public MyDataGridView()
        {
            InitializeComponent();
        }

        private void BtnQuery_Click(object sender, RoutedEventArgs e)
        {
            ConnectionConfig connectionConfig = new ConnectionConfig()
            {
                ConnectionString = "Server = localhost; Database = wpf; Uid = root; Pwd = 123456; ",
                IsAutoCloseConnection = true,
                DbType = DbType.MySql
            };
            using (SqlSugarClient db = new SqlSugarClient(connectionConfig))
            {
                List<Person> list = db.Queryable<Person>().ToList();
                dataGrid.ItemsSource = list;
                var list2 = db.Queryable<Person, Province>((p, s) => new JoinQueryInfos(JoinType.Left, p.ProvinceId == s.Id)).Select((p, s) => new
                {
                    ProvinceId = p.ProvinceId,
                    Name = s.Name
                }).ToList();
                var list3=db.Queryable<Province>().ToList();
                CboProvince.ItemsSource = list3;
            }
        }
    }
}
